﻿using AutoMapper;
using B.Z.BasicData.Domain.Entity.Excused;
using B.Z.BasicData.ErrorCode;
using B.Z.BasicData.Infrastructure;
using MediatR;

namespace B.Z.BasicData.API.Write.Application.ExcusedManage
{
    public class ExcuseShenpiCommandHandler : IRequestHandler<ExcuseShenpiCommand, APIResult<int>>
    {
        private readonly IBaseRepository<T_Excused> excuseRepository;
        private readonly IMapper mapper;

        public ExcuseShenpiCommandHandler(IBaseRepository<T_Excused> excuseRepository, IMapper mapper)
        {
            this.excuseRepository = excuseRepository;
            this.mapper = mapper;
        }

        public async Task<APIResult<int>> Handle(ExcuseShenpiCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = APIEnum.ok;
            result.Message = "审批成功";
            var model = mapper.Map<T_Excused>(request);
            model.Status = 1;
            result.Data = await excuseRepository.Update(model);
            return await Task.FromResult(result);
        }
    }
}
